fix58438: do not delete comments/code following unterminated string completion#58742
Conversation
Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
src/services/utilities.ts
Outdated
| export function createTextSpanFromStringLiteralLikeContent(node: StringLiteralLike, position?: number) { | ||
| let replacementEnd = node.getEnd() - 1; | ||
| if (node.isUnterminated) { | ||
| // we return no replacement range only if unterminated string is empty | ||
| if (node.getStart() === replacementEnd) return undefined; | ||
| replacementEnd = node.getEnd(); | ||
| replacementEnd = position !== undefined && position <= node.getEnd() ? position : node.getEnd(); |
There was a problem hiding this comment.
There are only two callers of createTextSpanFromStringLiteralLikeContent, and neither of them omit the position argument, so just make it required (and document what position is supposed to mean)
There was a problem hiding this comment.
Also, do you have any tests for when position is strictly greater than the end of the node? I don't think I'm seeing any.
There was a problem hiding this comment.
Ah, that was old code, thanks for catching it! (I tried to make position optional, but it ended up being needed in more places)
There was a problem hiding this comment.
It shouldn't be possible in a completion for position > node end but I will add that check incase createTextSpanFromStringLiteralLikeContent will be used in a non-completion context in the future.
There was a problem hiding this comment.
The only thing I can think of is possibly an unterminated string literal on the previous line
let s: "string" = "s
/*$*/There was a problem hiding this comment.
Completions won't be triggered on new lines -- so
type LongString = `asdf
string
line`
let s: LongString = `asdf
/**/
^ no suggestions
let r: LongString = `asdf/**/
^ completes to `asdf\nstring\nline`|
@typescript-bot cherry-pick to release-5.5 |
|
Hey, @DanielRosenwasser! I've created #58762 for you. |
…e-5.5 (#58762) Co-authored-by: Isabel Duan <isabelduan@microsoft.com>
fixes #58438
The above issue is a regression bug that happened because of #57839, which was included with 5.5 beta. This PR updates the
replacementRangeto be more inline with 5.4 behavior, namely completions on unterminated strings will not remove anything to the right of the cursor. Closed strings will replace everything within the quotes.Examples:
becomes
after completions are triggered at all three locations.